using System;
using System.Net;
using System.Net.Sockets;
using System.Collections;
using System.Collections.Generic;

class Server
{
    private Socket socket;

    public Server()
    {
        socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    }

    public void Start()
    {
        try
        {
            socket.Bind(new IPEndPoint(IPAddress.Any, 9999));
            socket.Listen(10);

            while (true)
            {
                Socket client = socket.Accept();

                User user = new User(client);
                user.Start();
                Console.WriteLine("Client connected {0} ({1} online)", client.LocalEndPoint.ToString(), User.Instances.Count);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
    }
}
